package com.julis.activity.log;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baseutils.SpfUtils;
import com.github.czy1121.view.RoundButton;

import com.julis.R;
import com.julis.base.BaseApplication;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class IPSActivity extends AppCompatActivity {

    @BindView(R.id.img_back)
    RelativeLayout imgBack;
    @BindView(R.id.tv_ftpip)
    TextView tvFtpip;
    @BindView(R.id.et_ftpip)
    EditText etFtpip;
    @BindView(R.id.tv_ftpport)
    TextView tvFtpport;
    @BindView(R.id.et_ftpport)
    EditText etFtpport;
    @BindView(R.id.tv_ftpyhm)
    TextView tvFtpyhm;
    @BindView(R.id.ed_ftpyhm)
    EditText edFtpyhm;
    @BindView(R.id.tv_ftpmima)
    TextView tvFtpmima;
    @BindView(R.id.et_ftpmima)
    EditText etFtpmima;

    @BindView(R.id.bt_getCode)
    RoundButton btGetCode;
    @BindView(R.id.activity_main)
    LinearLayout activityMain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ips);
        ButterKnife.bind(this);
        String hostname = (String) SpfUtils.get(BaseApplication.getInstance(), "hostname", "58.87.101.189");
        String port = (String) SpfUtils.get(BaseApplication.getInstance(), "port", "21");
        String username = (String) SpfUtils.get(BaseApplication.getInstance(), "username", "ftpuser");
        String password = (String) SpfUtils.get(BaseApplication.getInstance(), "password", "WWW.bjjuli.com..");
        String httpip = (String) SpfUtils.get(BaseApplication.getInstance(), "httpip", "http://39.107.101.184:8999");
        etFtpip.setText(hostname);
        etFtpport.setText(port);
        edFtpyhm.setText(username);
        etFtpmima.setText(password);


    }

    @OnClick({R.id.img_back, R.id.bt_getCode})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.bt_getCode:
                if (TextUtils.isEmpty(etFtpip.getText().toString())) {
                    Toast.makeText(this, "请输入FTP的地址！", Toast.LENGTH_SHORT).show();
                    return;

                }
                if (TextUtils.isEmpty(etFtpport.getText().toString())) {
                    Toast.makeText(this, "请输入FTP的端口！", Toast.LENGTH_SHORT).show();
                    return;

                }
                if (TextUtils.isEmpty(edFtpyhm.getText().toString())) {
                    Toast.makeText(this, "请输入FTP的用户名！", Toast.LENGTH_SHORT).show();
                    return;

                }
                if (TextUtils.isEmpty(etFtpmima.getText().toString())) {
                    Toast.makeText(this, "请输入FTP的密码！", Toast.LENGTH_SHORT).show();
                    return;

                }

                SpfUtils.put(BaseApplication.getInstance(), "hostname", etFtpip.getText().toString());
                 SpfUtils.put(BaseApplication.getInstance(), "port", etFtpport.getText().toString());
                SpfUtils.put(BaseApplication.getInstance(), "username", edFtpyhm.getText().toString());
                  SpfUtils.put(BaseApplication.getInstance(), "password", etFtpmima.getText().toString());


                Toast.makeText(this, "设置成功", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
